<%--
  Created by IntelliJ IDEA.
  User: Yy
  Date: 2022/5/24
  Time: 9:21
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/layui/css/layui.css">
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/layui/layui.js"></script>
    <script>
    layui.use(['table','util','jquery','layer','form'],function () {
        var table = layui.table, util = layui.util, $ = layui.jquery,
        layer = layui.layer, form = layui.form;
        //监听表单模糊查询
        form.on('submit(search-btn)',function (d) {
            var classId=$("#classId").val();
            var className=$("#className").val();
            table.reload('titleStu',{//指定条件重载table
                page:{page:1},
                where:{     //条件
                classId:classId,
                className:className,
                },
            });
        });

        //监听添加按钮
        $("#add-btn").click(function () {
            layer.open({
                type:2,//设置为iframe
                fix:false,//不固定
                maxmin:true,//出现最大化最小化按钮
                offset:'5px',//垂直水平位置
                shade:0.4,//遮罩层透明度
                area:['500px','700px'],//弹出层宽高
                title:"新增课程类别",//弹出层标题
                content:'${pageContext.request.contextPath}/stu/toaddctype'//弹出层内网页
            });
        });
        //监听工具栏按钮
        table.on('tool(demo)',function (res) {
            var row=res.data; //获取当前行的数据
            var event=res.event;//获取点的是哪个按钮
            var courseTypeId=row.courseTypeId;//获取行中的id列
            if (event=='del'){//删除用户
                layer.confirm("是否删除该课程类别？",{
                    btn:['确定','取消']
                },function() {
                    $.post("${pageContext.request.contextPath}/stu/delctype",{courseTypeId:courseTypeId},function (data) {
                        layer.msg(data.msg);//使用消息层 显示删除的结果
                        table.reload('titleStu',{
                            url:"${pageContext.request.contextPath}/stu/lookctype"
                        });
                    },"json");
                });
            };
            if(event=='edit'){
                layer.open({
                    type:2,//设置为iframe
                    fix:false,//不固定
                    maxmin:true,//出现最大化最小化按钮
                    offset:'10px',//垂直水平位置
                    shadeClose:true,
                    shade:0.4,//遮罩层透明度
                    area:['500px','700px'],//弹出层宽高
                    title:"修改课程类别",//弹出层标题
                    content:'${pageContext.request.contextPath}/stu/toupdctype/'+courseTypeId//弹出层内网页
                });
            };
        });
    });
    </script>
</head>
<body>
    <div>
        <a class="layui-btn" id="add-btn" lay-size="sm">添加</a>
    </div>
    <table class="layui-table" id="titleStu" lay-filter="demo" lay-size="sm"
           lay-data="{url:'${pageContext.request.contextPath}/stu/lookctype',page:true,id:'titleStu'}"
    >
        <thead>
        <tr>
            <th lay-data="{field:'courseTypeId',sort:true}">类别编号</th>
            <th lay-data="{field:'courseTypeName',sort:true}">类别名称</th>
            <th lay-data="{field:'remark',sort:true}">备注</th>
            <th lay-data="{toolbar:'#tools',align:'center',fixed:'right'}">操作</th>
        </tr>
        </thead>
    </table>
    <script type="text/html" id="tools">
        <a class="layui-btn layui-btn-xs" lay-event="edit">修改</a>
        <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</a>
    </script>
</body>
</html>
